package org.dromara.system.controller.talent;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.ServiceItemBo;
import org.dromara.system.domain.vo.ServiceItemVo;
import org.dromara.system.service.IServiceItemService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务项目
 *
 * @author Lion Li
 * @date 2025-07-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/talent/ServiceItem")
public class ServiceItemController extends BaseController {

    private final IServiceItemService serviceItemService;

    /**
     * 查询服务项目列表
     */
    @SaCheckPermission("talent:ServiceItem:list")
    @GetMapping("/list")
    public TableDataInfo<ServiceItemVo> list(ServiceItemBo bo, PageQuery pageQuery) {
        return serviceItemService.queryPageList(bo, pageQuery);
    }


    /**
     * 条件查询服务项目
     */
    @SaCheckPermission("talent:ServiceItem:list")
    @GetMapping("/findByCondition")
    public TableDataInfo<ServiceItemVo> findByCondition(ServiceItemBo bo, PageQuery pageQuery) {
        return serviceItemService.findByCondition(bo, pageQuery);
    }

    /**
     * 导出服务项目列表
     */
    @SaCheckPermission("talent:ServiceItem:export")
    @Log(title = "服务项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ServiceItemBo bo, HttpServletResponse response) {
        List<ServiceItemVo> list = serviceItemService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务项目", ServiceItemVo.class, response);
    }

    /**
     * 获取服务项目详细信息
     *
     * @param serviceItemId 主键
     */
    @SaCheckPermission("talent:ServiceItem:query")
    @GetMapping("/{serviceItemId}")
    public R<ServiceItemVo> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long serviceItemId) {
        return R.ok(serviceItemService.queryById(serviceItemId));
    }

    /**
     * 新增服务项目
     */
    @SaCheckPermission("talent:ServiceItem:add")
    @Log(title = "服务项目", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ServiceItemBo bo) {
        return toAjax(serviceItemService.insertByBo(bo));
    }

    /**
     * 修改服务项目
     */
    @SaCheckPermission("talent:ServiceItem:edit")
    @Log(title = "服务项目", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ServiceItemBo bo) {
        return toAjax(serviceItemService.updateByBo(bo));
    }

    /**
     * 删除服务项目
     *
     * @param serviceItemIds 主键串
     */
    @SaCheckPermission("talent:ServiceItem:remove")
    @Log(title = "服务项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceItemIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] serviceItemIds) {
        return toAjax(serviceItemService.deleteWithValidByIds(List.of(serviceItemIds), true));
    }
}
